﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AFSharedLibrary.Wizards;
using AFSharedLibrary;

namespace UIDesigner.Designers.Controls
{
    public class ctrlWizPanelConstructors : ctrlWizFrameBase
    {
        private ctrlCreateNewWizard m_ctrlContainer;

        #region " Windows Form Designer generated code "

        public ctrlWizPanelConstructors()
        {
            //This call is required by the Windows Form Designer.
            InitializeComponent();
        }

        //Form overrides dispose to clean up the component list.
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!(components == null))
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        private Label label1;
        private GroupBox groupBox1;
        public RadioButton optSelectDefaultConstructor;
        public RadioButton optCreateOptionsPanel;
        private FlowLayoutPanel flowLayoutPanel1;
        private Panel ConstructorsPanel;
        private TableLayoutPanel ConstructorListPanel;
        private Label label2;
        private Panel DefaultConstructorPanel;
        public CheckedListBox lstConstructors;

        //Required by the Windows Form Designer
        private System.ComponentModel.IContainer components;

        //NOTE: The following procedure is required by the Windows Form Designer
        //It can be modified using the Windows Form Designer.  
        //Do not modify it using the code editor.
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
            this.optCreateOptionsPanel = new System.Windows.Forms.RadioButton();
            this.ConstructorsPanel = new System.Windows.Forms.Panel();
            this.ConstructorListPanel = new System.Windows.Forms.TableLayoutPanel();
            this.label2 = new System.Windows.Forms.Label();
            this.optSelectDefaultConstructor = new System.Windows.Forms.RadioButton();
            this.DefaultConstructorPanel = new System.Windows.Forms.Panel();
            this.lstConstructors = new System.Windows.Forms.CheckedListBox();
            this.groupBox1.SuspendLayout();
            this.flowLayoutPanel1.SuspendLayout();
            this.ConstructorsPanel.SuspendLayout();
            this.ConstructorListPanel.SuspendLayout();
            this.DefaultConstructorPanel.SuspendLayout();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Dock = System.Windows.Forms.DockStyle.Top;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.Navy;
            this.label1.Location = new System.Drawing.Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(310, 18);
            this.label1.TabIndex = 0;
            this.label1.Text = "Multiple constructors detected";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // groupBox1
            // 
            this.groupBox1.AutoSize = true;
            this.groupBox1.Controls.Add(this.flowLayoutPanel1);
            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.groupBox1.Location = new System.Drawing.Point(0, 18);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(310, 248);
            this.groupBox1.TabIndex = 1;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Options";
            // 
            // flowLayoutPanel1
            // 
            this.flowLayoutPanel1.AutoSize = true;
            this.flowLayoutPanel1.Controls.Add(this.optCreateOptionsPanel);
            this.flowLayoutPanel1.Controls.Add(this.ConstructorsPanel);
            this.flowLayoutPanel1.Controls.Add(this.optSelectDefaultConstructor);
            this.flowLayoutPanel1.Controls.Add(this.DefaultConstructorPanel);
            this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
            this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 16);
            this.flowLayoutPanel1.Name = "flowLayoutPanel1";
            this.flowLayoutPanel1.Size = new System.Drawing.Size(304, 229);
            this.flowLayoutPanel1.TabIndex = 1;
            // 
            // optCreateOptionsPanel
            // 
            this.optCreateOptionsPanel.AutoSize = true;
            this.optCreateOptionsPanel.Checked = true;
            this.optCreateOptionsPanel.Location = new System.Drawing.Point(3, 3);
            this.optCreateOptionsPanel.Name = "optCreateOptionsPanel";
            this.optCreateOptionsPanel.Size = new System.Drawing.Size(125, 17);
            this.optCreateOptionsPanel.TabIndex = 0;
            this.optCreateOptionsPanel.TabStop = true;
            this.optCreateOptionsPanel.Text = "Create Options Panel";
            this.optCreateOptionsPanel.UseVisualStyleBackColor = true;
            // 
            // ConstructorsPanel
            // 
            this.ConstructorsPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.ConstructorsPanel.Controls.Add(this.ConstructorListPanel);
            this.ConstructorsPanel.Location = new System.Drawing.Point(20, 23);
            this.ConstructorsPanel.Margin = new System.Windows.Forms.Padding(20, 0, 0, 0);
            this.ConstructorsPanel.Name = "ConstructorsPanel";
            this.ConstructorsPanel.Size = new System.Drawing.Size(250, 18);
            this.ConstructorsPanel.TabIndex = 1;
            // 
            // ConstructorListPanel
            // 
            this.ConstructorListPanel.AutoScroll = true;
            this.ConstructorListPanel.AutoSize = true;
            this.ConstructorListPanel.ColumnCount = 1;
            this.ConstructorListPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.ConstructorListPanel.Controls.Add(this.label2, 0, 0);
            this.ConstructorListPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ConstructorListPanel.Location = new System.Drawing.Point(0, 0);
            this.ConstructorListPanel.Margin = new System.Windows.Forms.Padding(0);
            this.ConstructorListPanel.Name = "ConstructorListPanel";
            this.ConstructorListPanel.RowCount = 1;
            this.ConstructorListPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 16F));
            this.ConstructorListPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
            this.ConstructorListPanel.Size = new System.Drawing.Size(248, 16);
            this.ConstructorListPanel.TabIndex = 3;
            // 
            // label2
            // 
            this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
            this.label2.Location = new System.Drawing.Point(3, 0);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(242, 16);
            this.label2.TabIndex = 0;
            this.label2.Text = "Constructors";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // optSelectDefaultConstructor
            // 
            this.optSelectDefaultConstructor.AutoSize = true;
            this.optSelectDefaultConstructor.Location = new System.Drawing.Point(3, 44);
            this.optSelectDefaultConstructor.Name = "optSelectDefaultConstructor";
            this.optSelectDefaultConstructor.Size = new System.Drawing.Size(149, 17);
            this.optSelectDefaultConstructor.TabIndex = 0;
            this.optSelectDefaultConstructor.Text = "Select Default Constructor";
            this.optSelectDefaultConstructor.UseVisualStyleBackColor = true;
            this.optSelectDefaultConstructor.CheckedChanged += new System.EventHandler(this.optSelectDefaultConstructor_CheckedChanged);
            // 
            // DefaultConstructorPanel
            // 
            this.DefaultConstructorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.DefaultConstructorPanel.Controls.Add(this.lstConstructors);
            this.DefaultConstructorPanel.Location = new System.Drawing.Point(20, 64);
            this.DefaultConstructorPanel.Margin = new System.Windows.Forms.Padding(20, 0, 0, 0);
            this.DefaultConstructorPanel.Name = "DefaultConstructorPanel";
            this.DefaultConstructorPanel.Size = new System.Drawing.Size(250, 141);
            this.DefaultConstructorPanel.TabIndex = 1;
            this.DefaultConstructorPanel.Visible = false;
            // 
            // lstConstructors
            // 
            this.lstConstructors.Dock = System.Windows.Forms.DockStyle.Fill;
            this.lstConstructors.FormattingEnabled = true;
            this.lstConstructors.Location = new System.Drawing.Point(0, 0);
            this.lstConstructors.Margin = new System.Windows.Forms.Padding(0);
            this.lstConstructors.Name = "lstConstructors";
            this.lstConstructors.Size = new System.Drawing.Size(250, 139);
            this.lstConstructors.TabIndex = 0;
            this.lstConstructors.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.lstConstructors_ItemCheck);
            // 
            // ctrlWizPanelConstructors
            // 
            this.BackColor = System.Drawing.SystemColors.Control;
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label1);
            this.Name = "ctrlWizPanelConstructors";
            this.Size = new System.Drawing.Size(310, 266);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.flowLayoutPanel1.ResumeLayout(false);
            this.flowLayoutPanel1.PerformLayout();
            this.ConstructorsPanel.ResumeLayout(false);
            this.ConstructorsPanel.PerformLayout();
            this.ConstructorListPanel.ResumeLayout(false);
            this.DefaultConstructorPanel.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        public ctrlWizPanelConstructors(ctrlWizFrameBase ctrlPrevious, IWizardFrameContainer objContainer) : base(ctrlPrevious, objContainer)
        {
            Construct objConstruct;

            InitializeComponent();

            m_ctrlContainer = (ctrlCreateNewWizard)objContainer;
            objConstruct = m_ctrlContainer.BusinessObject;

            foreach (ConstructorMapItem objItem in objConstruct.ConstructorMap)
            {
                Label lblConstructor = new Label();
                RowStyle objStyle;

                lblConstructor.ForeColor = SystemColors.ControlDarkDark;  
                lblConstructor.Text = objItem.Name;
                lblConstructor.Dock = DockStyle.Fill;
                lblConstructor.Margin = new Padding(5, 0, 0, 0);
                lblConstructor.Padding = new Padding(0);

                ConstructorListPanel.RowCount++;
                ConstructorListPanel.Height += 22;
                ConstructorsPanel.Height += 22; 

                objStyle = new RowStyle();
                objStyle.SizeType = SizeType.AutoSize;

                ConstructorListPanel.RowStyles.Add(objStyle);

                ConstructorListPanel.Controls.Add(lblConstructor, 0, ConstructorListPanel.RowCount - 1);

                lstConstructors.Items.Add(objItem);
            }
        }

        public override string Caption
        {
            get 
            { 
                return "Multiple Constructors"; 
            }
        }

        public override System.Drawing.Image Image
        {
            get 
            { 
                return null; 
            }
        }

        public override ctrlWizFrameBase GetNextFrame(ctrlWizFrameBase ctrlPrevious)
        {
            if (object.ReferenceEquals(ctrlPrevious, this))
            {
                if (optCreateOptionsPanel.Checked)
                {
                    ctrlWizPanelOptionLabels ctrlPanel = new ctrlWizPanelOptionLabels(this, m_objContainer, 0);

                    return ctrlPanel;
                }
                else
                {
                    // TODO 
                }
            }
            else if (ctrlPrevious is ctrlWizPanelOptionLabels)
            {
                ctrlWizPanelOptionLabels ctrlPanelPrevious = (ctrlWizPanelOptionLabels)ctrlPrevious;
                Construct objConstruct = m_ctrlContainer.BusinessObject;

                if (ctrlPanelPrevious.ConstructorIndex + 1 < objConstruct.ConstructorMap.Count)
                {
                    ctrlWizPanelOptionLabels ctrlPanel = new ctrlWizPanelOptionLabels(ctrlPanelPrevious, m_objContainer, ctrlPanelPrevious.ConstructorIndex + 1);

                    return ctrlPanel;
                }
                else
                {
                    ctrlWizPanelButtonOptions ctrlPanel = new ctrlWizPanelButtonOptions(ctrlPanelPrevious, m_ctrlContainer);

                    return ctrlPanel;
                }
            }
            else if (ctrlPrevious is ctrlWizPanelButtonOptions)
            {
                ctrlWizPanelPanelOptions ctrlPanel = new ctrlWizPanelPanelOptions(ctrlPrevious, m_objContainer);

                return ctrlPanel;
            }

            return null;
        }

        private void optSelectDefaultConstructor_CheckedChanged(object sender, EventArgs e)
        {
            DefaultConstructorPanel.Visible = optSelectDefaultConstructor.Checked;  
        }

        private void lstConstructors_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked)
            {
                foreach (int nIndex in lstConstructors.CheckedIndices)
                {
                    if (nIndex != e.Index)
                    {
                        lstConstructors.SetItemChecked(nIndex, false);
                    }
                }
            }
        }
    }
}
